<?php

class pages extends Module {
	
	public function __construct () {
		parent::__construct (__CLASS__);
		
		$this->extend ('__custom_pages');
	}
	
	public function __default () {
		throw new NotFound;
	}
	
	public function show () {
		$pageName = getRequest ('param0');
		
		if (mb_strlen ($pageName) == 0) {
			throw new NotFound;
		}
		
		$oPageType = TypesController::getInstance()->getTypeByName ('page');
		
		$sel = new Selection;
		$sel->addType ($oPageType);
		$sel->addFilter ('alias', $pageName);
		$sel->addLimit (1);
		
		$res = $sel->getList ();
		
		if (count ($res) == 0) {
			throw new NotFound;
		}
		
		$oPage = ObjectsController::getInstance()->getObject ($oPageType, $res[0][0]);
		$oPage->disableHTMLFilter('text', false);
		$this->setPageTitle ($oPage->getValue ('title'));
		
		$response = new ModuleResponse;
		$response->addObject ($oPage);
		$response->setTemplate ('pages/show');
		
		return $response;
	}
	
}